
// race是返回数组中最快的结果，如果是reject则返回reject

const p1 = new Promise((resolve, reject) => {
  setTimeout(() => {
    resolve("resolve1");
  }, 1000);
});

const p2 = new Promise((resolve, reject) => {
  setTimeout(() => {
    reject("resolve2");
  }, 2000);
});

Promise.race([p1, p2])
  .then((res) => {
    console.log("resolve", res);
  })
  .catch((err) => {
    console.log("reject", err);
  });
